/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package biojavagoalz.string;

/**
 * String overlapping implementation
 * @author Tadas
 */
public class StringUtils implements StringOverlapFinder {

    /**
     * Example of Function Input and Result
     * x = "abcdefghijklm"
     * y = "hijklmnopqrst"
     * return: "abcdefg"
     *
     *
     */
    public String cleanX(String x, String y) {
        int matchCount = 0;

        outerX:
        for (int i = 0; i < x.length(); i++) {
            matchCount = 0;
            for (int j = 0; j < y.length() && i + j < x.length(); j++) {
                if (x.charAt(i + j) != y.charAt(j)) {
                        continue outerX;
                }
                
                if (++matchCount > 4 && i + j + 1 == x.length()) {
                    return x.substring(0, i);
                }
            }

        }

        return x;
    }
}
